package com.itheima.Demo;

import com.itheima.Utils.MybatisUtils;
import com.itheima.dao.UserMapper;
import com.itheima.pojo.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.Test;

import java.util.Date;
import java.util.List;

public class demo01 {
    @Test//查询
    public void Test01(){
        SqlSessionFactory sqlSessionFactory = MybatisUtils.getSqlSessionFactory();
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List L = mapper.findAll();
        L.forEach(l-> System.out.println(l.toString()));
        MybatisUtils.close(sqlSession);
    }
    @Test//添加
    public void Test02(){
        SqlSessionFactory sqlSessionFactory = MybatisUtils.getSqlSessionFactory();
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        mapper.addUser(new User(0,"Dale",new Date(),"男","上海"));
        MybatisUtils.close(sqlSession);
    }
    @Test//添加
    public void Test03(){
        SqlSessionFactory sqlSessionFactory = MybatisUtils.getSqlSessionFactory();
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        mapper.update(new User(6,"Harry",new Date(),"男","天庭"));
        MybatisUtils.close(sqlSession);
    }
    @Test//添加
    public void Test04(){
        SqlSessionFactory sqlSessionFactory = MybatisUtils.getSqlSessionFactory();
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        mapper.delete(6);
        MybatisUtils.close(sqlSession);
    }
}
